function autoInputAccount({ nationalTaxNo, nationalTaxPass, nationalTaxUser }) {
  deleteBox($('.layui-layer-page > span.layui-layer-setwin > a'));
  document.querySelector('#shxydmOrsbh').value = nationalTaxNo;
  document.querySelector('#userNameOrSjhm').value = nationalTaxUser;
  document.querySelector('#passWord').value = nationalTaxPass;
}
function deleteBox(boxs) {
  boxs = boxs || $('.layui-layer.layui-layer-iframe > span.layui-layer-setwin > a');
  if (boxs.length) {
    Array.from(boxs).forEach(ele => {
      ele.click();
    });
  }
}
const asyncSetInterval = async (fn, time = 200) => {
  return new Promise((resolve, reject) => {
    let timer = setInterval(() => {
      let result = fn();
      if (result) {
        clearInterval(timer);
        timer = null;
        resolve(result);
      }
    }, time);
  });
};

const ZDYpostMessage = (data, url = '*') => {
  data = JSON.stringify(data);
  window.postMessage(
    data,
    url
  );
};
const baoBiaoDetailBack = async (data, isclose = false, lastTime = 200) => {
  ZDYpostMessage({
    event: 'baoBiaoDetailBack',
    data: {
      type: data,
      isclose,
      lastTime
    }
  });
};

export {
  autoInputAccount,
  deleteBox,
  ZDYpostMessage,
  asyncSetInterval,
  baoBiaoDetailBack
};
